import sys


class ListNode:
    def __init__(self, val, child_list):
        self.val = val
        self.children = child_list  # List[str]


def ParseDomains(root, names, n):
    res = []
    
    def dfs(name, path):
        if not names[name].children:
            res.append('.'.join(path))
        for child in names[name].children:
            path = [child] + path
            dfs(child, path)
            path = path[1:]  # pop front
    
    dfs(root, path=[root])
    res = sorted(res)
    return res


if __name__ == "__main__":
    # n = int(sys.stdin.readline().strip())
    # names = dict()
    # for i in range(n):
    #     line = sys.stdin.readline().strip().split(' ')
    #     if line[0] not in names:
    #         names[line[0]] = ListNode(line[0], [])
    #     if line[1] not in names:
    #         names[line[1]] = ListNode(line[1], [line[0]])
    #     else:
    #         names[line[1]].children.append(line[0])
    # root = sys.stdin.readline().strip()  # com
    
    n = 5
    lines = ["www huawei", "career huawei", "huawei com", "google com", "sina com"]
    root = "com"
    names = dict()
    for line in lines:
        line = line.split(" ")
        if line[0] not in names:
            names[line[0]] = ListNode(line[0], [])
        if line[1] not in names:
            names[line[1]] = ListNode(line[1], [line[0]])
        else:
            names[line[1]].children.append(line[0])
    
    res = ParseDomains(root, names, n)
    for domain in res:
        print(domain)
